<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/taglibs.jsp" %>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css"/>
    <title>候选人查看列表</title>
</head>
<style>

    img { width: 100%; }

    * {
        margin: 0;
        padding: 0;
    }
    body{
        background-color: #F8F8F8!important;
        /*background-color: #EEF0F5;*/
    }

    .container{
        position: relative;
        top: -2rem;
        background-color: #F8F8F8;
        margin-left: auto;
        margin-right: auto;
        width: 84%;
    }

    .position-body{
        background-color: #f8f8f8;
    }
    .position {
        /*padding-bottom: 15px;*/
        /*border-bottom: solid 1px #CCCCCC;*/
        background-color: white;
        margin: 10px 0 3px 0;
        padding: 10px 5px 0 5px;
        border:0px solid;
        border-radius:5px;
        text-align: left;
    }

    .position_name {
        font-size: 15px;
        font-weight: bold;
        /*color: #0d71bb;*/
    }

    .position_person_image {
        font-size: 14px;
        font-weight: bold;
        color: #F47E2D;
        position: absolute;
        right: 0;
        z-index: 2;
        width: 50px;
        height: 50px;
        margin-right: 30px;
    }

    .avatar {
        width: 100%;
        right: 100%;
        display: block;
        border-radius: 100px;
    }

    .position_person_name {
        font-size: 13px;
        font-weight: bold;
        line-height: 32px;
        color: #61687C;
    }
    .domainName{
        color: white;
        background-color: #275eac;
    }

    .position_person_company {
        font-size: 13px;
        line-height: 16px;
        color: #61687C;
    }

    .position_person_experince {
        font-size: 10px;
        line-height: 30px;
        color: #ADADAD;
    }
    .no_more {
        color: #888;
        font-size: 10px;
        line-height: 35px;
        text-align: center;
        display: none;
    }
</style>
<body>
<div>
    <img src="${ctx}/resources/images/trend.jpg">
</div>
<div class="container">

    <div id="row-data" class="position-body">

        <c:choose>
            <c:when test="${recomlist == null or fn:length(recomlist)==0 }">
                <span style="text-align: center">没有相关候选人信息 </span>
            </c:when>
            <c:otherwise>
                <c:forEach items="${recomlist}" var="rp">
                    <div class="position" id="cc" data-positionid="${rp.id}" data-empid="${rp.personid}" data-jobid="${rp.jobid}" data-status="${rp.status}">
                        <input type="hidden" id="status" name="status" value="${rp.status}">
                        <input type="hidden" id="empid" name="empid" value="${rp.personid}">
                        <input type="hidden" id="jobid" name="jobid" value="${rp.jobid}">
                        <div class="position_name">应聘职位：${rp.positionname}</div>
                        <div class="position_image">
                            <div class="position_person_image">
                                <img class="avatar" src="${ctx}/resources/images/candidate_detail.jpg">
<%--                                <c:choose>--%>
<%--                                    <c:when test="{rp.avatar != null || rp.avatar == ''}">--%>
<%--                                        <img class="avatar" src="${rp.avatar}">--%>
<%--                                    </c:when>--%>
<%--                                    <c:otherwise>--%>
<%--                                        <img class="avatar" src="${ctx}/resources/images/head.jpg">--%>
<%--                                    </c:otherwise>--%>
<%--                                </c:choose>--%>

                            </div>

                            <div class="position_person_name">${rp.name} </div>
                            <div class="position_person_company"><span class="domainName">${rp.domainName}</span> &nbsp; ${rp.companyname} </div>
                        </div>
                        <div class="position_person_experince">
                                ${rp.roleName} | ${rp.cityName} | 工作${rp.workage}年
                        </div>


                    </div>


                </c:forEach>


            </c:otherwise>
        </c:choose>
    </div>
    <div class="no_more" id="noMore">没有更多内容了~</div>
</div>


<!-- 测试用，正式发布关闭 
<div id="testid">
点击获取更多数据
</div>
-->
<input type="hidden" name="lastposition" id="lastjob" value="0"/>
<input type="hidden" name="hasmoredata" id="hasmoredata" value="no"/>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

    wx.config({
        debug: false,
        appId: "${config.appid}",
        timestamp: ${config.currenttimestamp},
        nonceStr: "${config.nonceStr}",
        signature: "${config.signatureStr}",
        jsApiList: ['checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'showOptionMenu']
    });

    var datasource = {
        moredata: function () {
            var getUrl = '${ctx}/wechat/hunter/hr/morejobcandidate.do';
            var offset = $('#lastjob').val();
            var hasmore = $('#hasmoredata').val();

            getUrl += "?offset=" + offset;

            // if(hasmore != "yes"){
            //     console.log("已经没有更多数据了");
            //     return false;
            // }
            var that = this;

            $.ajax({
                url: getUrl,
                type: "GET",
                success: function (data, status) {
                    if (data.errorcode == 0) {
                        that.appenddata(data);
                    } else {
                        var errorUrl = '${ctx}/wechat/headhunter/error.page';
                        location.href = errorUrl;
                    }
                },
                error: function () {
                    alert("服务出错，请稍后尝试");
                }
            });
        },

        appenddata: function (data) {
            var offset = parseInt($('#lastjob').val());
            var divstring = "";
            var recomlist = data.data;

            var count = recomlist.length;
            offset += parseInt(count);
            $('#lastjob').val(offset);
            if (recomlist == null || count == 0) {
                $('#noMore').show();
                return;
            }
            $('#noMore').hide();

            for (var i in recomlist) {
                var rp = recomlist[i];

                divstring += "<div class='position' data-positionid='"+ rp.id +"' data-status='"+rp.status+"' data-jobid='"+rp.jobid +"' data-empid='"+rp.personid +"'>" +
                    "<div class='position_name'>职位：" + rp.positionname + "</div>\n" +
                    "<div class='position_image'>\n" +
                    "<div class='position_person_image'>\n";
                divstring += "<img class=\"avatar\" src=\"${ctx}/resources/images/candidate_detail.jpg\">";
                <%--if (rp.avatar != null) {--%>
                <%--    divstring += "<img class='avatar' src='" + rp.avatar + "'>\n";--%>
                <%--} else {--%>
                <%--    divstring += "<img class='avatar' src='${ctx}/resources/images/head.jpg'>\n";--%>
                <%--}--%>

                divstring +=
                    "</div>" +
                    "<div class='position_person_name'>" + rp.name + "</div>\n" +
                    "<div class='position_person_company'><span class='domainName'>" + rp.domainName + "</span>&nbsp;"+ rp.companyname   + "</div>\n" +
                    "</div>\n" +
                    "<div class='position_person_experince'>" + rp.roleName + "|" + rp.cityName + "| 工作" + rp.workage + "年\n" +
                    "</div>\n" +
                    "</div>"
            }

            var newdata = $(divstring);
            $('#row-data').append(newdata);
        }
    };

    $(document).ready(function () {

        var l = sessionStorage.getItem('index_list');

        if (null !== l && '' !== l) {
            $("#row-data").html(l);
            $(window).scrollTop(sessionStorage.getItem('index_scroll'));
            page = sessionStorage.getItem('index_page');
            sessionStorage.removeItem('index_list');
            sessionStorage.removeItem('index_scroll');
        }


        $(window).scroll(function () {
            if($(window).scrollTop() == $(document).height() - $(window).height()) {
                datasource.moredata();
            }
        });


        $('#row-data').on('click', '.position', function () {
            var offset = $('#lastjob').val();
            var positionid = $(this).attr('data-positionid');
            var status = $(this).attr('data-status') == null ? 0 :  $(this).attr('data-status');
            var jobid = $(this).attr('data-jobid');
            var empid = $(this).attr('data-empid');
            var getUrl;

            if (parseInt(status) == 1 || parseInt(status) == 2 || parseInt(status) == 3 || parseInt(status) == 7) {
                getUrl = '${ctx}/wechat/hunter/hr/toInterview.do?recommendid=' + positionid;
            } else if (parseInt(status) == 0 || parseInt(status) == 4 || parseInt(status) == 5 || parseInt(status) == 6 || parseInt(status) == 8) {
                getUrl = '${ctx}/wechat/hunter/hr/toViewCandidate.do?recommendid=' + positionid + '&empid=' + empid + '&jobid=' + jobid + '&status=' + status;
            }
            sessionStorage.setItem('index_list', $("#row-data").html());
            sessionStorage.setItem('index_page', offset);
            sessionStorage.setItem('index_scroll', $(window).scrollTop());
            window.location.href = getUrl;
        });

        wx.ready(function () {
            wx.onMenuShareAppMessage({
                title: 'Headoffer--专业招聘平台----推荐有奖！',
                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: 'Headoffer--专业招聘平台----推荐有奖！',
                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
            });

            wx.showOptionMenu();

        });

    });

</script>
</body>
</html>